<template>
    <!-- 期中结算报送审批 -->
    <base-breadcrumb>
        <searchData :searchData="searchArr" @search="search"></searchData>
        <a-card>
<!--            <div>-->
<!--                <a-button-->
<!--                    class="mb12"-->
<!--                    v-btnPermission="'bm_032_add_01'"-->
<!--                    type="primary"-->
<!--                    icon="plus"-->
<!--                    @click="handleManage(2)"-->
<!--                    >新增</a-button-->
<!--                >-->
<!--            </div>-->
            <list-table
                ref="table"
                size="default"
                rowKey="key"
                :columns="columns"
                :request="loadData"
                :alert="true"
                show-size-changer
                show-quick-jumper
                showPagination="auto"
                :isShowCountBar="false"
                :exportConfig="{ use: true,select: '总包期中结算',all: '总包期中结算'}"
                :exportPermission="{ select: 'bm_032_exp_03', all: 'bm_032_exp_03' }"
            >
                <a-alert type="info" show-icon slot="bottom">
                    <template slot="message">
                        <span>
                            报审值(含税)(万元):
                            <a>{{ statistics.totalReportValueContainTax }}</a>
                        </span>
                        <a-divider type="vertical" />
                        <span>
                            实际成本(含税)(万元):
                            <a>{{ statistics.totalFactValueContainTax }}</a>
                        </span>
                        <a-divider type="vertical" />
                        <span>
                            审定金额(含税)(万元):
                            <a>{{ statistics.totalGuaranteedFee }}</a>
                        </span>
                        <a-divider type="vertical" />
                        <span>
                            利润额(含税)(万元):
                            <a>{{ statistics.totalReportFee }}</a>
                        </span>
                        <a-divider type="vertical" />
                        <span>
                            利润率%:
                            <a>{{ statistics.totalReportRate }}</a>
                        </span>
                    </template>
                </a-alert>
                              <span
                                      slot="serial"
                                      slot-scope="text, record, index"
                              >{{ index + 1 }}</span>
                <span slot="description" slot-scope="text">
                    <ellipsis :length="8" tooltip>{{ text }}</ellipsis>
                </span>
                <span slot="operation" slot-scope="text, record">
                    <MoreButton>
                    <a v-btnPermission="'bm_032_loo_02'" @click="handleManage(0, record)">查看</a>
                    <!-- 编辑 -->
                    <span
                        v-btnPermission="'bm_032_edi_01'"
                        v-if="
                            (record.status != 'SUBMITTED' &&
                            record.status != 'PAST' &&
                            record.status != 'ABOLISH' &&
                            record.status != 'UPLOAD')&&hideBuquBtn()
                        "
                    >
                        <a @click="handleManage(1, record)">编辑</a>
                    </span>
                    <!-- 撤销 -->
<!--                    <span v-if="record.status == 'SUBMITTED'&&selfBtnShow(record.creatorId)">-->
<!--                        <a @click="handleUndo({ id: record.id, type: 3 })">撤销</a>-->
<!--                    </span>-->
<!--                    &lt;!&ndash; 作废 &ndash;&gt;-->
<!--                    <span v-if="record.status == 'PAST'" v-btnPermission="'bm_032_tov_05'">-->
<!--                        <a @click="handleInvalid({ id: record.id, type: 2 })">作废</a>-->
<!--                    </span>-->
<!--                    &lt;!&ndash; 删除 &ndash;&gt;-->
<!--                    <span-->
<!--                        v-if="record.status == 'DRAFT' || record.status == 'REJECTED'"-->
<!--                        v-btnPermission="'bm_032_del_03'"-->
<!--                    >-->
<!--                        <a @click="handleRemoveParams({ id: record.id, type: 1 })">删除</a>-->
<!--                    </span>-->

<!--                    <span-->
<!--                        v-btnPermission="'bm_032_loo_04'"-->
<!--                        v-if="-->
<!--                            record.status === 'PAST' ||-->
<!--                            record.status === 'SUBMITTED' ||-->
<!--                            record.status === 'REJECTED' ||-->
<!--                            record.status === 'ABOLISH' ||-->
<!--                            record.status === 'UPLOAD'-->
<!--                        "-->
<!--                    >-->
<!--                        <approval-button :status="record.status" :id="record.id"></approval-button>-->
<!--                    </span>-->
                        </MoreButton>
                </span>
            </list-table>
        </a-card>
    </base-breadcrumb>
</template>

<script>
import BasePage from '@/views/basePage' // 基础配置
import { getApprovalTermList, delApprovalTerm, getApprovalTermCount } from '@/api/businessAffairs/revenueAndCost'
import OrgTreeSelect from '@/components/OrgTreeSelect'
import { position } from './model.js'
const columns = [
    {
        title: '序号',
        width: '65px',
        scopedSlots: { customRender: 'serial' }
    },
    {
        title: '所属分公司',
        dataIndex: 'branchComName'
    },
    {
        title: '所属项目',
        dataIndex: 'projectName'
    },
    {
        title: '名称',
        dataIndex: 'name'
    },
    {
        title: '结算部位',
        dataIndex: 'partName'
    },
    {
        title: '报审值(含税)(万元)',
        dataIndex: 'reportValueContainTax'
    },
    {
        title: '实际成本(含税)(万元)',
        dataIndex: 'factValueContainTax'
    },
    {
        title: '审定金额(含税)(万元)',
        dataIndex: 'guaranteedFee'
    },
    {
        title: '利润额(含税)(万元)',
        dataIndex: 'guaranteedRate'
    },
    {
        title: '利润率%',
        dataIndex: 'reportRate'
    },
    {
        title: '填报人',
        dataIndex: 'creatorName'
    },

    {
        title: '填报时间',
        dataIndex: 'createTime'
    },
    {
        title: '状态',
        dataIndex: 'statusName',
    },
    {
        title: '操作',
        dataIndex: 'operation',
        width: '230px',
        fixed: 'right',
        scopedSlots: { customRender: 'operation' }
    }
]
const searchArr = [
{
    name: '所属单位',
    valueKey: 'searchQuery',
    type: OrgTreeSelect,
  },
    // {
    //     name: '所属分公司',
    //     valueKey: 'branchComId',
    //     type: SelectSubCompany
    // },
    // {
    //     name: '所属项目',
    //     keyValue: 'branchComId',
    //     valueKey: 'projectId',
    //     type: SelectProject
    // },
    {
        name: '名称',
        value: 'name',
        type: 'input'
    },
    {
        name: '结算部位',
        value: 'partName',
        type: 'input',
        // data: position
    },
    {
        name: '填报人',
        value: 'creatorName',
        type: 'input'
    },
    {
        name: '填报时间',
        type: 'dateRange',
        value: 'activityDate',
        attr: {
            rangeFormat: ['createTimeBegin', 'createTimeEnd']
        }
    },
    {
        name: '状态',
        value: 'auditStatus',
        type: 'select',
        data: [
            {
                value: '0',
                label: '待提交'
            },
            {
                value: '1',
                label: '已提交'
            },
        ]
    }
]
import { typeListApproval } from '@/utils/util'
import { STable } from '@/components'
export default {
    name: 'a' + Date.now(),
    extends: new BasePage(),
    components: {
        STable
    },
    data() {
        this.columns = columns
        this.searchArr = searchArr
        return {
            queryParam: {},
            userId: JSON.parse(sessionStorage.getItem('ycloud-user_info')).id,
            removeApi: {
                remove: delApprovalTerm,
                invalid: delApprovalTerm,
                undo: delApprovalTerm
            }, // api
            statistics: {
                totalFactValueContainTax: 0,
                totalGuaranteedFee: 0,
                totalReportFee: 0,
                totalReportRate: 0,
                totalReportValueContainTax: 0
            },
            loadData: async (parameter) => {
                const requestParameters = Object.assign({}, parameter, this.queryParam)
                this.getApprovalTermCountReq(requestParameters)
                const [err, res] = await getApprovalTermList(requestParameters)
                res.data.forEach(item=>{
                    item.statusName = item.status === 'DRAFT' ? '待提交': '已提交'
                })
                return new Promise((resolve, reject) => {
                    if (err) {
                        reject(err)
                    } else {
                        res.data.forEach(item=>{
                            if(!item.creatorName) {
                                item.createTime = ''
                            }
                        })
                        resolve(res)
                    }
                })
            }
        }
    },

    methods: {
        //搜索
        search(value) {
            value && (this.queryParam = value)
            console.log(value)
            this.$refs.table.refresh(true)
        },
        //统计
        async getApprovalTermCountReq(requestParameters) {
            const [err, res] = await getApprovalTermCount(requestParameters)
            if (!err) {
                this.statistics = res.data
            } else {
                this.$message.warning(err.data.message)
            }
        },
        // 操作栏
        handleManage(type, record) {
            let query = {
                editModel: type
            }
            if (record && record.id) {
                query.id = record.id
            }
            this.$router.push({
                name: 'updateSettlementFinalized',
                query
            })
        }
    }
}
</script>


